use std::sync::Arc;

use crate::{
    cache::installed::InstalledRepo, cli::AlterOption, default::DEFAULT_RPMDB_LOCATION,
    repo::CmdRepo, solve::SolveContext, Rdnf,
};
use anyhow::Result;
#[derive(Debug, Clone)]
pub enum AlterType {
    AutoErase,
    AutoEraseAll,
    DownGrade,
    DownGradeAll,
    Erase,
    Install,
    ReInstall,
    Upgrade,
    UpgradeAll,
    DistroSync,
    Obsoleted,
}
impl Rdnf {
    pub async fn alter_command(
        self,
        pkgs: Vec<String>,
        _alter_type: AlterType,
        _alter_args: AlterOption,
    ) -> Result<()> {
        let mut repos = Rdnf::make_cache(
            self.repo_confs,
            self.conf.config_main.clone(),
            self.cli,
            self.term,
        )
        .await?;
        repos.sort_by(|a, b| b.config.base.priority.cmp(&a.config.base.priority));
        let installed_repo =
            InstalledRepo::open(&self.conf.config_main, DEFAULT_RPMDB_LOCATION).await?;
        let (cmd_repo, _) = CmdRepo::new(Vec::<&str>::new()).await?;
        let mut solve_context = SolveContext::new(repos, installed_repo, cmd_repo);
        for pkg in pkgs {
            solve_context.add_pkg_from_repo(Arc::new(pkg)).await?;
        }
        solve_context.solve().await?;
        Ok(())
    }
}
